#!/usr/bin/env python2.7
# -*- coding:utf-8 -*- 

# clean_buckets.py

import os, sys
from metlib.kits import *
from filecache.models import *

def run():
    try:
        buckets = FileCacheBucket.objects.all()
        for bucket in buckets:
            print "Cleaning Bucket %s:" % bucket.name
            old_size = bucket.used_size
            bucket.clear_cache()
            new_size = bucket.used_size
            M_ratio = float(1024*1024)
            print "    old: %.1f M, new: %.1f M" % (old_size/M_ratio, new_size/M_ratio)
    except Exception as e:
        print e

